﻿using System;
using System.Configuration;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using KPIS.DBM;
using KPIS.GERP.GAMS.MODEL;


namespace KPIS.GERP.GAMS.DAL
{
    public sealed class D_ACM_Finance_Payment 
    {
        DBManager dbManager = new DBManager(SystemInfo._DataProvider, SystemInfo._ConnectionString);
        ConvertNullable cn = new ConvertNullable();
        D_ACM_Finance_Recive ACMRecive = new D_ACM_Finance_Recive();

        public IList<M_ACM_Finance_Payment> GetListFullDataPayment(string strMonth, string strYear)
        {
            string strSQL;
            DataRowCollection drc = null;
            IList<M_ACM_Finance_Payment> infoList = new List<M_ACM_Finance_Payment>();
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);
                dbManager.AddParameters(0, "@month", strMonth);
                dbManager.AddParameters(1, "@year", string.IsNullOrEmpty(strYear) ? "0" : (Convert.ToInt32(strYear) - 543).ToString());

                strSQL = "select a.pay_seq as pay_seq ,a.pay_name as pay_name,a.amount as amount,a.pay_date as pay_date"
                    + " from fim_payments a"
                    + " left join fim_payment_cheques b on a.pay_seq=b.pay_seq"
                        + " and b.record_status not like 'D'"
                    + " left join fim_cheques c on c.cheque_seq =b.cheque_seq"
                        + " and b.record_status not like 'D'"
                    + " where a.record_status = 'A'"
                    + " and ((a.method_seq = 2 and MONTH(c.pay_date)=@month and YEAR(c.pay_date)=@year)"
                        + " or (a.method_seq != 2 and MONTH(a.real_pay_date)=@month and YEAR(a.real_pay_date)=@year))";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_ACM_Finance_Payment info = new M_ACM_Finance_Payment();
                        info.pay_seq = Convert.ToInt32(drc[i]["pay_seq"]);
                        info.pay_name = drc[i]["pay_name"].ToString();
                        info.amount = Convert.ToDouble(drc[i]["amount"]);
                        info.pay_date= Convert.ToDateTime(drc[i]["pay_date"]);

                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public string Insert_Transaction(M_ACM_GENERAL_Ledger info)
        {
            string strSQL;
            string strSeq;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(11);
                dbManager.BeginTransaction();
                dbManager.AddParameters(0, "@fiscal_period", info.fiscal_period);
               
                dbManager.AddParameters(1, "@tran_code", info.tran_code);
                dbManager.AddParameters(2, "@tran_date", info.tran_date);
               
               
                dbManager.AddParameters(3, "@tran_name", info.tran_name);
                dbManager.AddParameters(4, "@remarks", info.remark);
                dbManager.AddParameters(5, "@record_status", info.record_status);
                dbManager.AddParameters(6, "@created_by", info.created_by);
                dbManager.AddParameters(7, "@created_when", info.created_when);
                dbManager.AddParameters(8, "@tran_type", info.tran_type);
                dbManager.AddParameters(9, "@ref_no", info.ref_no);
                dbManager.AddParameters(10, "@bgm_year", info.bgm_year);

                strSQL = " INSERT INTO acm_transection "
                        + " (fiscal_period,tran_code,tran_date"
                        + " ,tran_name,remarks,record_status,created_by,created_when,tran_type,ref_no, bgm_year)"
                        + "  VALUES "
                        + " (@fiscal_period,@tran_code,@tran_date"
                        + " ,@tran_name,@remarks,@record_status,@created_by,@created_when,@tran_type,@ref_no, @bgm_year)"
                        + " select scope_identity();";
                strSeq = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows[0][0].ToString();
               
                dbManager.CommitTransaction();
            }
            catch (Exception ex)
            {
                dbManager.RollBackTransaction();
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return strSeq;
        }
        public void Insert_DB_CR(M_ACM_GENERAL_Ledger info)//acm_transection_dtls
        {
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(7);
                dbManager.AddParameters(0, "@tran_seq", info.tran_seq);
                dbManager.AddParameters(1, "@account_seq", info.account_seq);
                dbManager.AddParameters(2, "@dr_or_cr", info.dr_or_cr);
                dbManager.AddParameters(3, "@amount", info.amount);
                dbManager.AddParameters(4, "@record_status", info.record_status);
                dbManager.AddParameters(5, "@created_by", info.created_by);
                dbManager.AddParameters(6, "@created_when", info.created_when);

                strSQL = " INSERT INTO acm_transection_dtls "
                        + "(tran_seq,account_seq,dr_or_cr,amount,record_status,created_by,created_when)"
                        + " VALUES (@tran_seq,@account_seq,@dr_or_cr,@amount,@record_status,@created_by,@created_when) ";

                dbManager.ExecuteNonQuery(CommandType.Text, strSQL);
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public Dictionary<string, decimal> GetvalueAccPP(string selectmonth, string BgmYear, string BgmSourceSeq)
        {
            Dictionary<string, decimal> ret = new Dictionary<string, decimal>();
            DataRowCollection drc = null;
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(3);
                //dbManager.AddParameters(0, "@SelectMonth", selectmonth);
                dbManager.AddParameters(0, "@BgmYear", BgmYear);
                dbManager.AddParameters(1, "@month", selectmonth);
                dbManager.AddParameters(2, "@bgm_source_seq", BgmSourceSeq);
                //query join 3 table  
                //acm_transection 
                //acm_transection_dtls
                //acm_mas_base_account
                strSQL = "select b.dr_or_cr as dr_or_cr , b.amount as amount"
                + " from acm_transection a right join acm_transection_dtls b on a.tran_seq = b.tran_seq"
                + " left join acm_mas_base_account MbaseAcc  on b.account_seq = MbaseAcc.buy_v_sale_vat_account_seq "
                + " and b.account_seq = MbaseAcc.buy_vat_account_seq and b.account_seq = MbaseAcc.sale_vat_account_seq" 
                + " where a.record_status not like 'D'"
                + " and a.bgm_source_seq = @bgm_source_seq"
                + " and year(a.tran_date) = @BgmYear and month(a.tran_date) = @month order by dr_or_cr desc";
                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;

                if (drc.Count > 0)
                {                    
                    string[] strArray = new string[drc.Count];
                    decimal[] amountArray = new decimal[drc.Count];

                    for (int i = 0; i < drc.Count; i++)
                    {
                        strArray[i] = Convert.ToString(drc[i]["dr_or_cr"] == null ? 0 : drc[i]["dr_or_cr"]);
                        amountArray[i] = Convert.ToDecimal(drc[i]["amount"] == null ? 0 : drc[i]["amount"]);
                    }
                    
                    string[] arr1 = { "Dr", "Dr", "Cr" };string[] arr2 = { "Dr", "Cr", "Cr" };
                    string[] arr3 = { "Dr", "Cr", "Cr", "Cr" };string[] arr4=  { "Dr", "Dr", "Cr", "Cr" }; 

                    string strSumPayAmount = "";
                    //string strSumReceiveAmount = "";

                    if (strArray.SequenceEqual(arr1, StringComparer.OrdinalIgnoreCase)) 
                    {
                        strSumPayAmount = SumPaytaxAmount(selectmonth, BgmYear, "sumPayTax");
                        ret.Add("sumBuyAmount", !string.IsNullOrEmpty(strSumPayAmount) ? Convert.ToDecimal(strSumPayAmount) : 0);//ราคารวมยอดซื้อ
                        ret.Add("sumSaleAmount", ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=""
                            && ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=null?Convert.ToDecimal(ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")):0);//รวมราคาขายของเดือนที่เลือก
                        ret.Add("taxSale", Convert.ToDecimal(amountArray[0]));//ภาษีขาย
                        ret.Add("amountDr", Convert.ToDecimal(amountArray[1]));//ลุกหนี้สรรพากร
                        ret.Add("taxBuy", Convert.ToDecimal(amountArray[2]));//บัญชีภาษีซื้อ
                    }
                    else if (strArray.SequenceEqual(arr2, StringComparer.OrdinalIgnoreCase))
                    {
                        strSumPayAmount = SumPaytaxAmount(selectmonth, BgmYear, "sumPay");
                        ret.Add("sumBuyAmount", !string.IsNullOrEmpty(strSumPayAmount) ? Convert.ToDecimal(strSumPayAmount) : 0);//ราคารวมยอดซื้อ
                        ret.Add("sumSaleAmount", ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=""
                            && ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=null?Convert.ToDecimal(ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")):0);//รวมราคาขายของเดือนที่เลือก
                        ret.Add("taxSale", Convert.ToDecimal(amountArray[0]));//ภาษีขาย
                        ret.Add("taxBuy", Convert.ToDecimal(amountArray[1]));//ภาษีซื้อ
                        ret.Add("amountDr", Convert.ToDecimal(amountArray[2]));//ลูกหนี้สรรพากร (ภาษีที่ต้องชำระ)

                    }
                    else if (strArray.SequenceEqual(arr3, StringComparer.OrdinalIgnoreCase))
                    {
                        strSumPayAmount = SumPaytaxAmount(selectmonth, BgmYear, "sumPay");
                        ret.Add("sumBuyAmount", !string.IsNullOrEmpty(strSumPayAmount) ? Convert.ToDecimal(strSumPayAmount) : 0);//ราคารวมยอดซื้อ
                        ret.Add("sumSaleAmount", ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=""
                            && ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=null?Convert.ToDecimal(ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")):0);//รวมราคาขายของเดือนที่เลือก
                        ret.Add("taxSale", Convert.ToDecimal(amountArray[0]));//ภาษีขาย
                        ret.Add("amountDr", Convert.ToDecimal(amountArray[1]));//ลูกหนี้สรรพากร (ภาษีที่ต้องชำระ)
                        ret.Add("taxBuy", Convert.ToDecimal(amountArray[2]));//ภาษีซื้อ
                        ret.Add("amountCr", Convert.ToDecimal(amountArray[3]));//เจ้าหนี้สรรพากร

                    }
                    else if (strArray.SequenceEqual(arr4, StringComparer.OrdinalIgnoreCase))
                    {
                        strSumPayAmount = SumPaytaxAmount(selectmonth, BgmYear, "sumPay");
                        ret.Add("sumBuyAmount", !string.IsNullOrEmpty(strSumPayAmount) ? Convert.ToDecimal(strSumPayAmount) : 0);//ราคารวมยอดซื้อ
                        ret.Add("sumSaleAmount", ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=""
                            && ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")!=null?Convert.ToDecimal(ACMRecive.SumRecivetaxAmount(selectmonth,"SumRecive")):0);//รวมราคาขายของเดือนที่เลือก
                        ret.Add("taxSale", Convert.ToDecimal(amountArray[0]));//ภาษีขาย
                        ret.Add("amountDr", Convert.ToDecimal(amountArray[1]));//ลูกหนี้สรรพากร (ภาษีที่ต้องชำระ)
                        ret.Add("taxBuy", Convert.ToDecimal(amountArray[2]));//ภาษีซื้อ
                        ret.Add("amountCr", Convert.ToDecimal(amountArray[3]));//เจ้าหนี้สรรพากร (ภาษีที่ต้องชำระ)

                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (dbManager.Connection != null) dbManager.Dispose();
            }

            return ret;
        }

        public IList<M_ACM_Finance_Payment> GetvalueAccPND(int? month, int? year, int? source, int? contact_type)
        {
            // Dictionary<string, decimal> ret = new Dictionary<string, decimal>();
            IList<M_ACM_Finance_Payment> ret = new List<M_ACM_Finance_Payment>();
            DataTable drc = null;
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(4);
                dbManager.AddParameters(0, "@Month", month);
                dbManager.AddParameters(1, "@Year", year);
                dbManager.AddParameters(2, "@Type", (contact_type != null ? contact_type : 0));
                dbManager.AddParameters(3, "@source", source);

                strSQL = "SELECT fr.pay_seq,fr.receipt_no,fr.pay_date"
                + " ,fr.contact_seq,case when imc.NameTh is null then imc.NameEng else imc.NameTh end as ContactName"
                + " ,Concat(case when imc.Address is null then '' else 'ที่อยู่ '+imc.Address end"
                + " ,case when imc.Lane is null then '' else ' '+imc.Lane end"
                + " ,case when imc.Road is null then '' else ' ถนน '+imc.Road end"
                + " ,case when imc.District is null then '' else ' '+imc.District end"
                + " ,case when imc.Amphur is null then '' else ' '+imc.Amphur end"
                + " ,case when imc.Province is null then '' else ' '+imc.Province end) as contact_addr"
                + " ,imc.ConGrpId as ContactGroup,iml.LookUpName ContactGroupName,imc.TaxCode"
                + " ,isnull(fr.ref_no,'') as ref_no,fr.pay_name,isnull(fr.amount,0) - isnull(fr.vat,0) as amount"
                + " ,isnull(fr.tax_rate,0) as tax_rate,isnull(fr.tax,0) as tax,fr.created_by,fr.created_when"
                + " ,mrd.total_amount as pr_amount, fr.vat, fr.money_req_seq"
                + " FROM fim_payments fr"
                + " LEFT JOIN IcmMasContact imc ON imc.ConId = fr.contact_seq"
                + " LEFT JOIN IcmMasLookUp iml ON iml.LookUpId = imc.ConGrpId"
                //+ " LEFT JOIN fim_mas_events frt ON frt.event_seq = fr.event_seq"
                // Adding for Total Amount on 4/6/57 ต้องการยอดรวม
                + " LEFT JOIN (select mrd.money_req_seq"
                        + ", max(coalesce(mrd.percent_vat, 0)) as percent_vat, max(coalesce(mrd.percent_tax, 0)) as percent_tax"
                        + ", sum(coalesce(mrd.amount, 0)) as total_amount"
                        + ", sum(coalesce(mrd.amount_tax, 0)) as total_amount_tax"
                        + " from fim_money_request_dtls mrd"
                        + " where mrd.record_status not like 'D'"
                        + " group by mrd.money_req_seq"
                        + ") mrd ON fr.money_req_seq = mrd.money_req_seq"
                + " WHERE fr.record_status = 'A' AND fr.contact_seq is not null AND fr.amount is not null "
                //+ " WHERE fr.record_status != 'D' AND fr.contact_seq is not null AND fr.amount is not null AND fr.tax is not null "
                + (month != null ? " AND MONTH(fr.pay_date) = @Month" : "")
                + (year != null ? " AND YEAR(fr.pay_date)  = @Year" : "")
                + (source != null ? " AND fr.bgm_source_seq  = @source" : "")
                + (contact_type != null ? " AND imc.ConGrpId  = @Type" : "")
                + "";
                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];

                if (drc.Rows.Count > 0)
                {
                    for (int i = 0; i < drc.Rows.Count; i++)
                    {
                        M_ACM_Finance_Payment item = new M_ACM_Finance_Payment();
                        item.remarks = drc.Rows[i]["contact_addr"].ToString();
                        item.contact_name = drc.Rows[i]["ContactName"].ToString();
                        item.amount = cn.ConvertNullDouble(drc.Rows[i]["amount"]);
                        item.tax = cn.ConvertNullDouble(drc.Rows[i]["tax"]);
                        item.contact_person_name = drc.Rows[i]["TaxCode"].ToString();
                        item.pay_date = cn.ConvertNullDateTime(drc.Rows[i]["pay_date"]);
                        item.ref_no = drc.Rows[i]["ref_no"].ToString();
                        item.pay_name = drc.Rows[i]["pay_name"].ToString();
                        item.tax_rate = cn.ConvertNullDouble(drc.Rows[i]["tax_rate"]);
                        //(drc[i]["tax"] != null ? Convert.ToDecimal(drc[i]["tax"]) : 0);
                        //item.tax_rate = (drc[i]["tax_rate"] != null ? Convert.ToDecimal(drc[i]["tax_rate"]) : 0);
                        item.pr_amount = cn.ConvertNullDouble(drc.Rows[i]["pr_amount"]);
                        item.vat = cn.ConvertNullDouble(drc.Rows[i]["vat"]);
                        item.money_req_seq = cn.ConvertNullInt(drc.Rows[i]["money_req_seq"]);
                        ret.Add(item);
                    }

                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (dbManager.Connection != null) dbManager.Dispose();
            }

            return ret;
        }

        public IList<M_ACM_Finance_Payment> GetList()
        {         
            string strSQL;
            
            DataRowCollection drc = null;
            IList<M_ACM_Finance_Payment> infoList = new List<M_ACM_Finance_Payment>();
            try
            {
                dbManager.Open();

                strSQL = "select a.pay_seq as pay_seq ,a.pay_name as pay_name,a.amount as amount,a.real_pay_date as real_pay_date  from fim_payments a left join fim_payment_cheques b  on a.pay_seq=b.pay_seq  left join  fim_cheques c on  c.cheque_seq =b.cheque_seq  where real_pay_date <> ''";

                drc = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0].Rows;
                if (drc.Count > 0)
                {
                    for (int i = 0; i < drc.Count; i++)
                    {
                        M_ACM_Finance_Payment info = new M_ACM_Finance_Payment();
                        info.pay_seq = Convert.ToInt32(drc[i]["pay_seq"]);
                        info.pay_name = drc[i]["pay_name"].ToString();
                        info.amount = Convert.ToDouble(drc[i]["amount"]);
                        info.real_pay_date = Convert.ToDateTime(drc[i]["real_pay_date"]);

                        infoList.Add(info);
                    }
                }
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
            }

            return infoList;
        }

        public string SumPaytaxAmount(string strMonth, string strYear, string ProcessName)
        {
            try
            {
                //Decimal drc;
                string strSQL;

                //DataRowCollection drc = null;
                dbManager.Open();
               
                dbManager.CreateParameters(2);
                dbManager.AddParameters(0, "@month", strMonth);
                dbManager.AddParameters(1, "@year", strYear);
                if (strMonth != null && ProcessName == "sumPayTax")
                {
                    strSQL = "select sum(coalesce(a.tax, 0) + coalesce(b.amount, 0)) as amount"
                        + " from fim_payments a"
                        + " left join fim_payment_cheques b on a.pay_seq=b.pay_seq"
                            + " and b.record_status not like 'D'"
                        + " left join fim_cheques c on c.cheque_seq =b.cheque_seq"
                            + " and b.record_status not like 'D'"
                        + " where a.record_status = 'A'"
                        + " and (a.real_pay_date is NULL OR MONTH(a.real_pay_date)=@month)"
                        + " and (a.method_seq NOT LIKE 2 OR MONTH(c.pay_date)=@month)";
                }
                else if (strMonth != null && ProcessName == "sumPay")
                {
                    strSQL = "select sum(coalesce(a.amount, 0)) as amount"
                        + " from fim_payments a"
                        + " left join fim_payment_cheques b on a.pay_seq=b.pay_seq"
                            + " and b.record_status not like 'D'"
                        + " left join fim_cheques c on c.cheque_seq =b.cheque_seq"
                            + " and b.record_status not like 'D'"
                        + " where a.record_status = 'A'"
                        + " and (a.real_pay_date is NULL OR MONTH(a.real_pay_date)=@month)"
                        + " and (a.method_seq NOT LIKE 2 OR MONTH(c.pay_date)=@month)";
                }
                else
                {
                    strSQL = "select sum(coalesce(a.tax, 0)) as amount"
                        + " from fim_payments a"
                        + " left join fim_payment_cheques b on a.pay_seq=b.pay_seq"
                            + " and b.record_status not like 'D'"
                        + " left join fim_cheques c on c.cheque_seq =b.cheque_seq"
                            + " and b.record_status not like 'D'"
                        + " where a.record_status = 'A'"
                        + " and (a.real_pay_date is NULL OR MONTH(a.real_pay_date)=@month)"
                        + " and (a.method_seq NOT LIKE 2 OR MONTH(c.pay_date)=@month)";
                }
                    DataTable dt = new DataTable();
                dt = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
                if (dt.Rows.Count > 0)
                {
                    return dt.Rows[0][0].ToString().Length > 0 ? dt.Rows[0][0].ToString() : "0";
                }
                else
                {
                    return "0";
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
            }
        }

        public DataTable ReportTaxPay(int? month,int? year)
        {
            DataTable dt = new DataTable();
            string strSQL;
            try
            {
                dbManager.Open();
                dbManager.CreateParameters(2);
                dbManager.AddParameters(0, "@Strmonth", month);
                dbManager.AddParameters(1, "@stryear", year);

                strSQL = "select ROW_NUMBER()OVER(ORDER BY a.pay_seq DESC) AS Row ,a.real_pay_date as real_pay_date,'-',d.NameTh  as ConName,d.TaxCode as TaxConCode,'-','-',a.amount as amount"
                        + " ,(case isnull(a.vat,0) when 0 then 0 else (coalesce(a.amount, 0) - coalesce(a.vat, 0)) END )as amountExCludeVat ,isnull(a.vat,0) as Vat"
                        +" from fim_payments a left join fim_payment_cheques b on a.pay_seq=b.pay_seq"
                        +" left join fim_cheques c on c.cheque_seq =b.cheque_seq"
                        +" left join IcmMasContact d on d.ConId = a.contact_seq"
                        +" where a.record_status = 'A'and b.record_status not Like 'D' and c.record_status<>'D' "
                        + " and (a.real_pay_date is NULL OR MONTH(a.real_pay_date)=@Strmonth)"
                        + " and (a.method_seq NOT LIKE 2 OR MONTH(c.pay_date)=@Strmonth)  and a.event_seq='11'  and a.bgm_year=@stryear "
                        + " and a.vat > 0";
   
                dt = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];
            }
            catch (Exception ex)
            {
                throw (ex);
            }
            finally
            {
                dbManager.Dispose();
        }
      
            return dt;
        }

        public string getBgmOperaProjCode(string money_req_seq)
        {
            string bgmProjOperCode = string.Empty;
            string strSQL = string.Empty;
            DataTable dt = new DataTable();

            try
            {
                dbManager.Open();
                dbManager.CreateParameters(1);
                dbManager.AddParameters(0, "@money_req_seq", money_req_seq);

                strSQL = string.Format("SELECT op.bgm_proj_oper_code FROM fim_payments fr LEFT JOIN fim_money_requests mr ON fr.money_req_seq = mr.money_req_seq LEFT JOIN bgm_project_operation op ON  mr.bgm_proj_oper_seq = op.bgm_proj_oper_seq WHERE fr.money_req_seq = {0}", "@money_req_seq");

                dt = dbManager.ExecuteDataSet(CommandType.Text, strSQL).Tables[0];

                if (dt.Rows.Count > 0)
                {
                    bgmProjOperCode = dt.Rows[0][0].ToString().Length > 0 ? dt.Rows[0][0].ToString() : string.Empty;
                }
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dbManager.Dispose();
        }
      
            return bgmProjOperCode;
        }
    }
}
